﻿using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PrearrangedChaos.AgileZen.Service.Model;
using PrearrangedChaos.AgileZen.Service.Rest;

namespace PrearrangedChaos.AgileZen.Service.Integrationtests
{
    [TestClass]
    public class SerializationTest
    {
        [TestMethod]
        public void Serialization_Attachment_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Attachment));
            var actual = serializer.Deserialize(File.OpenRead("Attachment.xml")) as Attachment;

            Assert.AreEqual("text/plain", actual.ContentType);
            Assert.AreEqual("plans.txt", actual.FileName);
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(3142, actual.SizeInBytes);
            Assert.AreEqual("22d72579249a4e1693075219e29b80a6", actual.Token);
        }

        [TestMethod]
        public void Serialization_Comment_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Comment));
            var actual = serializer.Deserialize(File.OpenRead("Comment.xml")) as Comment;

            Assert.IsNotNull(actual.Author);
            Assert.IsInstanceOfType(actual.Author, typeof(User));
            Assert.AreEqual(new DateTime(2011, 2, 17, 20, 1, 1), actual.CreateTime);
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual("No way we can build it in 2 weeks.", actual.Text);
        }

        [TestMethod]
        public void Serialization_Invite_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof (Invite));
            var actual = serializer.Deserialize(File.OpenRead("Invite.xml")) as Invite;

            Assert.IsNotNull(actual.Role);
            Assert.AreEqual(3, actual.Role.Id);
            Assert.AreEqual("Administrators", actual.Role.Name);
            Assert.IsNotNull(actual.Sender);
            Assert.AreEqual("Gob@bluth.com", actual.Sender.Email);
            Assert.AreEqual(1, actual.Sender.Id);
            Assert.AreEqual("Gob Bluth", actual.Sender.Name);
            Assert.AreEqual("gob", actual.Sender.UserName);
            Assert.AreEqual("7072d4c39059432ea791a03407463f7c", actual.Token);
            Assert.AreEqual(new DateTime(2011, 2, 25, 16, 53, 9), actual.CreateTime);
            Assert.AreEqual("georgesr@bluth.com", actual.Email);
            Assert.AreEqual(1, actual.Id);
        }

        [TestMethod]
        public void Serialization_User_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(User));
            var actual = serializer.Deserialize(File.OpenRead("User.xml")) as User;

            Assert.AreEqual("Gob@bluth.com", actual.Email);
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual("Gob Bluth", actual.Name);
            Assert.AreEqual("gob", actual.UserName);
            Assert.AreEqual("Some bio", actual.Bio);
            Assert.AreEqual(new DateTime(2011, 2, 17, 20, 1, 1), actual.CreateTime);
        }

        [TestMethod]
        public void Serialization_User_WithStories_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(User));
            var actual = serializer.Deserialize(File.OpenRead("UserWithStories.xml")) as User;

            Assert.IsNotNull(actual.Stories);
            Assert.IsInstanceOfType(actual.Stories, typeof(ReadOnlyCollection<IStory>));
            Assert.AreEqual(8, actual.Stories.Count);
            Assert.IsInstanceOfType(actual.Stories[0], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[1], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[2], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[3], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[4], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[5], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[6], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[7], typeof(Story));
        }

        [TestMethod]
        public void Serialization_Phase_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Phase));
            var actual = serializer.Deserialize(File.OpenRead("Phase.xml")) as Phase;

            Assert.AreEqual("Stories that will be worked on someday", actual.Description);
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(3, actual.Index);
            Assert.AreEqual(5, actual.Limit);
            Assert.AreEqual("Backlog", actual.Name);
        }

        [TestMethod]
        public void Serialization_PhaseNullValues_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Phase));
            var actual = serializer.Deserialize(File.OpenRead("PhaseNullValues.xml")) as Phase;

            Assert.IsNull(actual.Limit);
        }

        [TestMethod]
        public void Serialization_Phase_WithStories_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Phase));
            var actual = serializer.Deserialize(File.OpenRead("PhaseWithStories.xml")) as Phase;

            Assert.IsNotNull(actual.Stories);
            Assert.IsInstanceOfType(actual.Stories, typeof(ReadOnlyCollection<IStory>));
            Assert.AreEqual(4, actual.Stories.Count);
            Assert.IsInstanceOfType(actual.Stories[0], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[1], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[2], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[3], typeof(Story));
        }

        [TestMethod]
        public void Serialization_Project_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("Project.xml")) as Project;

            Assert.AreEqual(new DateTime(2011, 2, 17, 18, 47, 16), actual.CreateTime);
            Assert.AreEqual("I can see myself marinating a chicken in that.", actual.Description);
            Assert.AreEqual(1, actual.Id);
            Assert.IsNotNull(actual.Owner);
            Assert.IsInstanceOfType(actual.Owner, typeof(User));
            Assert.AreEqual("Sudden Valley", actual.Name);
        }

        [TestMethod]
        public void Serialization_Project_WithDetails_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("ProjectWithDetails.xml")) as Project;

            Assert.AreEqual("Some details", actual.Details);
        }

        [TestMethod]
        public void Serialization_Project_WithInvites_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("ProjectWithInvites.xml")) as Project;

            Assert.IsNotNull(actual.Invites);
            Assert.IsInstanceOfType(actual.Invites, typeof(ReadOnlyCollection<IInvite>));
            Assert.AreEqual(2, actual.Invites.Count);
            Assert.IsInstanceOfType(actual.Invites[0], typeof(Invite));
            Assert.IsInstanceOfType(actual.Invites[1], typeof(Invite));
        }

        [TestMethod]
        public void Serialization_Project_WithMembers_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("ProjectWithMembers.xml")) as Project;

            Assert.IsNotNull(actual.Members);
            Assert.IsInstanceOfType(actual.Members, typeof(ReadOnlyCollection<IUser>));
            Assert.AreEqual(8, actual.Members.Count);
            Assert.IsInstanceOfType(actual.Members[0], typeof(User));
            Assert.IsInstanceOfType(actual.Members[1], typeof(User));
            Assert.IsInstanceOfType(actual.Members[2], typeof(User));
            Assert.IsInstanceOfType(actual.Members[3], typeof(User));
            Assert.IsInstanceOfType(actual.Members[4], typeof(User));
            Assert.IsInstanceOfType(actual.Members[5], typeof(User));
            Assert.IsInstanceOfType(actual.Members[6], typeof(User));
            Assert.IsInstanceOfType(actual.Members[7], typeof(User));
        }

        [TestMethod]
        public void Serialization_Project_WithMetrics_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("ProjectWithMetrics.xml")) as Project;

            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual.Metrics, typeof(ProjectMetrics));
        }

        [TestMethod]
        public void Serialization_Project_WithPhases_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("ProjectWithPhases.xml")) as Project;

            Assert.IsNotNull(actual.Phases);
            Assert.IsInstanceOfType(actual.Phases, typeof(ReadOnlyCollection<IPhase>));
            Assert.AreEqual(5, actual.Phases.Count);
            Assert.IsInstanceOfType(actual.Phases[0], typeof(Phase));
            Assert.IsInstanceOfType(actual.Phases[1], typeof(Phase));
            Assert.IsInstanceOfType(actual.Phases[2], typeof(Phase));
            Assert.IsInstanceOfType(actual.Phases[3], typeof(Phase));
            Assert.IsInstanceOfType(actual.Phases[4], typeof(Phase));
        }

        [TestMethod]
        public void Serialization_Project_WithRoles_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Project));
            var actual = serializer.Deserialize(File.OpenRead("ProjectWithRoles.xml")) as Project;

            Assert.IsNotNull(actual.Roles);
            Assert.IsInstanceOfType(actual.Roles, typeof(ReadOnlyCollection<IRole>));
            Assert.AreEqual(2, actual.Roles.Count);
            Assert.IsInstanceOfType(actual.Roles[0], typeof(Role));
            Assert.IsInstanceOfType(actual.Roles[1], typeof(Role));
        }

        [TestMethod]
        public void Serialization_Tag_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Tag));
            var actual = serializer.Deserialize(File.OpenRead("Tag.xml")) as Tag;

            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual("come on", actual.Name);
        }

        [TestMethod]
        public void Serialization_Tag_WithStories_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Tag));
            var actual = serializer.Deserialize(File.OpenRead("TagWithStories.xml")) as Tag;

            Assert.IsNotNull(actual.Stories);
            Assert.IsInstanceOfType(actual.Stories, typeof(ReadOnlyCollection<IStory>));
            Assert.AreEqual(2, actual.Stories.Count);
            Assert.IsInstanceOfType(actual.Stories[0], typeof(Story));
            Assert.IsInstanceOfType(actual.Stories[1], typeof(Story));
        }

        [TestMethod]
        public void Serialization_Task_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Task));
            var actual = serializer.Deserialize(File.OpenRead("Task.xml")) as Task;

            Assert.AreEqual(new DateTime(2011, 2, 17, 20, 01, 40), actual.CreateTime);
            Assert.AreEqual(new DateTime(2011, 2, 17, 20, 03, 17), actual.FinishTime);
            Assert.IsNotNull(actual.FinishedBy);
            Assert.IsInstanceOfType(actual.FinishedBy, typeof(User));
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(TaskStatus.Incomplete, actual.Status);
            Assert.AreEqual("Get George Michael to help", actual.Text);
        }

        [TestMethod]
        public void Serialization_Role_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Role));
            var actual = serializer.Deserialize(File.OpenRead("Role.xml")) as Role;

            Assert.IsNotNull(actual.Members);
            Assert.IsInstanceOfType(actual.Members, typeof(ReadOnlyCollection<IUser>));
            Assert.AreEqual(3, actual.Members.Count);
            Assert.IsInstanceOfType(actual.Members[0], typeof(User));
            Assert.IsInstanceOfType(actual.Members[1], typeof(User));
            Assert.IsInstanceOfType(actual.Members[2], typeof(User));
            Assert.AreEqual(3, actual.Id);
            Assert.AreEqual(ApiAccess.Read, actual.Access);
            Assert.AreEqual("Administrators", actual.Name);
        }

        [TestMethod]
        public void Serialization_Story_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("Story.xml")) as Story;

            Assert.IsNotNull(actual.Creator);
            Assert.IsInstanceOfType(actual.Creator, typeof(User));
            Assert.IsNotNull(actual.Owner);
            Assert.IsInstanceOfType(actual.Owner, typeof(User));
            Assert.IsNotNull(actual.Phase);
            Assert.IsInstanceOfType(actual.Phase, typeof(Phase));
            Assert.IsNotNull(actual.Project);
            Assert.IsInstanceOfType(actual.Project, typeof(Project));
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(StoryColor.Teal, actual.Color);
            Assert.AreEqual(new DateTime(2011, 2, 24, 0, 0, 0), actual.Deadline);
            Assert.AreEqual("9", actual.Priority);
            Assert.AreEqual("5", actual.Size);
            Assert.AreEqual(StoryStatus.Started, actual.Status);
            Assert.AreEqual("Build Spec house", actual.Text);
        }

        [TestMethod]
        public void Serialization_Story_WithComments_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithComments.xml")) as Story;

            Assert.IsNotNull(actual.Comments);
            Assert.IsInstanceOfType(actual.Comments, typeof(ReadOnlyCollection<IComment>));
            Assert.AreEqual(2, actual.Comments.Count);
            Assert.IsInstanceOfType(actual.Comments[0], typeof(Comment));
            Assert.IsInstanceOfType(actual.Comments[1], typeof(Comment));
        }

        [TestMethod]
        public void Serialization_Story_WithDetails_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithDetails.xml")) as Story;

            Assert.AreEqual("Only have 2 weeks to build a spec house to announce to the press.", actual.Details);
        }

        [TestMethod]
        public void Serialization_Story_WithMetrics_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithMetrics.xml")) as Story;

            Assert.IsNotNull(actual.Metrics);
            Assert.IsInstanceOfType(actual.Metrics, typeof(StoryMetrics));
        }

        [TestMethod]
        public void Serialization_Story_WithMilestones_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithMilestones.xml")) as Story;

            Assert.IsNotNull(actual.Milestones);
            Assert.IsInstanceOfType(actual.Milestones, typeof(ReadOnlyCollection<IMilestone>));
            Assert.AreEqual(3, actual.Milestones.Count);
            Assert.IsInstanceOfType(actual.Milestones[0], typeof(Milestone));
            Assert.IsInstanceOfType(actual.Milestones[1], typeof(Milestone));
            Assert.IsInstanceOfType(actual.Milestones[2], typeof(Milestone));
        }

        [TestMethod]
        public void Serialization_Story_WithSteps_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithSteps.xml")) as Story;

            Assert.IsNotNull(actual.Steps);
            Assert.IsInstanceOfType(actual.Steps, typeof(ReadOnlyCollection<IStep>));
            Assert.AreEqual(3, actual.Steps.Count);
            Assert.IsInstanceOfType(actual.Steps[0], typeof(Step));
            Assert.IsInstanceOfType(actual.Steps[1], typeof(Step));
            Assert.IsInstanceOfType(actual.Steps[2], typeof(Step));

        }

        [TestMethod]
        public void Serialization_Story_WithTags_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithTags.xml")) as Story;

            Assert.IsNotNull(actual.Tags);
            Assert.IsInstanceOfType(actual.Tags, typeof(ReadOnlyCollection<ITag>));
            Assert.AreEqual(4, actual.Tags.Count);
            Assert.IsInstanceOfType(actual.Tags[0], typeof(Tag));
            Assert.IsInstanceOfType(actual.Tags[1], typeof(Tag));
            Assert.IsInstanceOfType(actual.Tags[2], typeof(Tag));
            Assert.IsInstanceOfType(actual.Tags[3], typeof(Tag));
        }

        [TestMethod]
        public void Serialization_Story_WithTasks_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryWithTasks.xml")) as Story;

            Assert.IsNotNull(actual.Tasks);
            Assert.IsInstanceOfType(actual.Tasks, typeof(ReadOnlyCollection<ITask>));
            Assert.AreEqual(4, actual.Tasks.Count);
            Assert.IsInstanceOfType(actual.Tasks[0], typeof(Task));
            Assert.IsInstanceOfType(actual.Tasks[1], typeof(Task));
            Assert.IsInstanceOfType(actual.Tasks[2], typeof(Task));
            Assert.IsInstanceOfType(actual.Tasks[3], typeof(Task));
        }

        [TestMethod]
        public void Serialization_Story_NullValues_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Story));
            var actual = serializer.Deserialize(File.OpenRead("StoryNullValues.xml")) as Story;

            Assert.AreEqual(null, actual.Priority);
            Assert.AreEqual(null, actual.Size);
        }

        [TestMethod]
        public void Serialization_ProjectMetrics_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProjectMetrics));
            var actual = serializer.Deserialize(File.OpenRead("ProjectMetrics.xml")) as ProjectMetrics;

            Assert.AreEqual(0.45, actual.BlockedTime);
            Assert.AreEqual(0.01, actual.CycleTime);
            Assert.AreEqual(99.99, actual.Efficiency);
            Assert.AreEqual(0.01, actual.LeadTime);
            Assert.AreEqual(3.4, actual.Throughput);
            Assert.AreEqual(0.48, actual.WaitTime);
            Assert.AreEqual(0.05, actual.WorkTime);
        }

        [TestMethod]
        public void Serialization_StoryMetrics_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(StoryMetrics));
            var actual = serializer.Deserialize(File.OpenRead("StoryMetrics.xml")) as StoryMetrics;

            Assert.AreEqual(new DateTime(2011, 2, 17, 19, 26, 17), actual.StartTime);
            Assert.AreEqual(new DateTime(2011, 2, 17, 19, 26, 3), actual.CreateTime);
        }

        [TestMethod]
        public void Serialization_Milestone_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Milestone));
            var actual = serializer.Deserialize(File.OpenRead("Milestone.xml")) as Milestone;

            Assert.AreEqual(new DateTime(2011, 2, 17, 20, 21, 20), actual.StartTime);
            Assert.AreEqual(TimeSpan.FromSeconds(694909), actual.Duration);
            Assert.AreEqual(31, actual.Id);
            Assert.IsNotNull(actual.Phase);
            Assert.IsInstanceOfType(actual.Phase, typeof(Phase));
        }

        [TestMethod]
        public void Serialization_Step_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Step));
            var actual = serializer.Deserialize(File.OpenRead("Step.xml")) as Step;

            Assert.AreEqual(new DateTime(2011, 2, 17, 19, 26, 03), actual.StartTime);
            Assert.AreEqual(TimeSpan.FromSeconds(1180), actual.Duration);
            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual("working", actual.Type);
            Assert.AreEqual(new DateTime(2011, 2, 17, 19, 45, 43), actual.EndTime);
        }

        [TestMethod]
        public void Serialization_GetCommentsResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(CommentCollection));
            var actual = serializer.Deserialize(File.OpenRead("Comments.xml")) as CommentCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Comment[]));
            Assert.AreEqual(2, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(2, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetInvitesResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(InviteCollection));
            var actual = serializer.Deserialize(File.OpenRead("Invites.xml")) as InviteCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Invite[]));
            Assert.AreEqual(2, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(2, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetPhasesResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PhaseCollection));
            var actual = serializer.Deserialize(File.OpenRead("Phases.xml")) as PhaseCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Phase[]));
            Assert.AreEqual(5, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(5, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetTagsResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TagCollection));
            var actual = serializer.Deserialize(File.OpenRead("Tags.xml")) as TagCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Tag[]));
            Assert.AreEqual(3, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(3, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetAttachmentsResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(AttachmentCollection));
            var actual = serializer.Deserialize(File.OpenRead("Attachments.xml")) as AttachmentCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Attachment[]));
            Assert.AreEqual(2, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(2, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetProjectsResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProjectCollection));
            var actual = serializer.Deserialize(File.OpenRead("Projects.xml")) as ProjectCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Project[]));
            Assert.AreEqual(2, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(2, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetTasksResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TaskCollection));
            var actual = serializer.Deserialize(File.OpenRead("Tasks.xml")) as TaskCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Task[]));
            Assert.AreEqual(4, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(4, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetRolesResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(RoleCollection));
            var actual = serializer.Deserialize(File.OpenRead("Roles.xml")) as RoleCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Role[]));
            Assert.AreEqual(2, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(2, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetStoriesResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(StoryCollection));
            var actual = serializer.Deserialize(File.OpenRead("Stories.xml")) as StoryCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Story[]));
            Assert.AreEqual(16, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(16, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetMyStoriesResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(MyStoriesCollection));
            var actual = serializer.Deserialize(File.OpenRead("Stories.xml")) as MyStoriesCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Story[]));
            Assert.AreEqual(16, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(16, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetTagStoriesResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TagStoriesCollection));
            var actual = serializer.Deserialize(File.OpenRead("Stories.xml")) as TagStoriesCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Story[]));
            Assert.AreEqual(16, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(16, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetProjectMembersResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ProjectMembersCollection));
            var actual = serializer.Deserialize(File.OpenRead("Users.xml")) as ProjectMembersCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(User[]));
            Assert.AreEqual(8, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(8, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetRoleMembersResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(RoleMembersCollection));
            var actual = serializer.Deserialize(File.OpenRead("Users.xml")) as RoleMembersCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(User[]));
            Assert.AreEqual(8, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(8, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

        [TestMethod]
        public void Serialization_GetStoryTagsResponse_Test()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(StoryTagsCollection));
            var actual = serializer.Deserialize(File.OpenRead("Tags.xml")) as StoryTagsCollection;

            Assert.IsNotNull(actual.Items);
            Assert.IsInstanceOfType(actual.Items, typeof(Tag[]));
            Assert.AreEqual(3, actual.Items.Length);
            Assert.AreEqual(1, actual.Page);
            Assert.AreEqual(100, actual.PageSize);
            Assert.AreEqual(3, actual.TotalItems);
            Assert.AreEqual(1, actual.TotalPages);
        }

    }
}
